package com.example.test.quartz;

import com.example.test.bean.OrderInfoBO;
import com.example.test.service.WybzService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Configurable;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.List;

@Component
@Configurable
@EnableScheduling
public class Task {

    @Autowired
    private WybzService wybzService;

    @Scheduled(cron = "0 15 10 ? * *")
    public void test(){
        System.out.println("spring定时任务方法");
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");//设置日期格式
//        String createTime = dateFormat.format(now);//格式化然后放入字符串中
        Calendar c = Calendar.getInstance();

        c.add(Calendar.DATE, - 3);

        Date time = c.getTime();

        String preDay = dateFormat.format(time);
        List<OrderInfoBO> orderInfoList = wybzService.getOrderInfoByCreateTime(preDay);

        wybzService.sendMsg(orderInfoList);
    }
}